package com.keehin.migrate;

import java.sql.SQLException;

import com.keehin.Database;

public class MigrateSale {
	protected static Database srcDB;
	protected static Database descDB;

	public static void main(String[] args) {
		try {
			System.out.println(args[0]);
			System.out.println(args[1]);
			System.out.println(args[2]);
			System.out.println(args[3]);
			srcDB = new Database(new com.mysql.jdbc.Driver(), "jdbc:mysql://"
					+ args[0] + "?characterEncoding=tis620", args[2], args[3]);
			if (srcDB != null)
				System.out.println(srcDB + " OK");
			descDB = new Database(new com.mysql.jdbc.Driver(), "jdbc:mysql://"
					+ args[1] + "?characterEncoding=tis620", args[2], args[3]);
			if (descDB != null)
				System.out.println(descDB + " OK");
		} catch (SQLException e) {
			e.printStackTrace();
		}

		descDB.executeUpdate("delete from docukind");
		descDB.executeUpdate("insert into windmill.docukind(comCode,docCode, descript, runNo) select '"
				+ args[4] + "', docukind, Description, 0 from migrate.docukind");

		descDB.executeUpdate("delete from rreason");
		descDB.executeUpdate("insert into windmill.rreason(comCode,resCode, descript, stockUpdate) select '"
				+ args[4]
				+ "', code, reason, stockSensitive='Y' from migrate.rreason");

//		descDB.executeUpdate("update docukind set runNo = (select  from migrate.company) where docCode='A'");
//		descDB.executeUpdate("update docukind set runNo = (select  from migrate.company) where docCode='B'");
//		descDB.executeUpdate("update docukind set runNo = (select CreditInvoiceNumber from migrate.company) where docCode='C'");
//		descDB.executeUpdate("update docukind set runNo = (select  from migrate.company) where docCode='D'");
//		descDB.executeUpdate("update docukind set runNo = (select CashInvoiceNumber from migrate.company) where docCode='I'");
//		descDB.executeUpdate("update docukind set runNo = (select  from migrate.company) where docCode='J'");
//		descDB.executeUpdate("update docukind set runNo = (select  from migrate.company) where docCode='K'");
//		descDB.executeUpdate("update docukind set runNo = (select  from migrate.company) where docCode='O'");
//		descDB.executeUpdate("update docukind set runNo = (select  from migrate.company) where docCode='P'");
//		descDB.executeUpdate("update docukind set runNo = (select  from migrate.company) where docCode='R'");
//		descDB.executeUpdate("update docukind set runNo = (select  from migrate.company) where docCode='S'");
//		descDB.executeUpdate("update docukind set runNo = (select  from migrate.company) where docCode='T'");
	}

	public static void printSymbol(int i) {
		if (i % 500 == 0) {
			System.out.print("#");
			if (i % 100000 == 0)
				System.out.printf("%,10d\n", i);
			else if (i % 50000 == 0)
				System.out.println();
		}
	}
}
